// This file is part of OpenTSDB.
// Copyright (C) 2017 TeleDB Development Group.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version.  This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.  You should have received a copy
// of the GNU Lesser General Public License along with this program.  If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.utils.hbase;

import net.opentsdb.utils.Assert;
import org.hbase.async.HBaseClient;
import org.hbase.async.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 扫描hbase表信息，对scanner封装
 */
public class HbaseScanner {
    private static final Logger LOG = LoggerFactory.getLogger(HbaseScanner.class);

    private HbaseScanner(final Builder builder){ }

    public static Builder builder(HBaseClient client, byte[] table){
        return new Builder(client, table);
    }

    public final static class Builder{

        private Scanner scanner;

        private Builder(HBaseClient client, byte[] table){
            Assert.notNull(client," hbase client con't be null ");
            Assert.notNull(table," table con't be null ");

            scanner = client.newScanner(table);
        }


        public Builder startKey(byte[] startKey){
            scanner.setStartKey(startKey);
            return this;
        }

        public Builder endKey(byte[] endKey){
            scanner.setStopKey(endKey);
            return this;
        }

        public Builder family(byte[] family){
            scanner.setFamily(family);
            return this;
        }

        public Builder qulitifer(byte[] qulitifer){
            scanner.setQualifier(qulitifer);
            return this;
        }

        public Builder maxNumRows(int maxNumRows){
            scanner.setMaxNumRows(maxNumRows);
            return this;
        }

        public HbaseScanner buid(){
            return new HbaseScanner(this);
        }

    }
}
